package org.springframework.beans.factory.support;

import org.springframework.beans.factory.config.SingletonBeanRegistry;

import javax.naming.spi.ObjectFactory;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 山顶洞人郑某
 * @className DefaultSingletonBeanRegistry.java 默认的单列bean注册器
 * @date 2025 04 21
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    /**
     * 一级缓存
     */
    private Map<String,Object> singletonObjects = new HashMap<>();
    // TODO 后期通过三级缓存解决依赖循环
    /**
     * 获取单例对象
     *
     * @param beanName
     * @return
     */
    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }

    /**
     * 添加单列bean
     *
     * @param beanNam
     * @param bean
     */
    @Override
    public void addSingleton(String beanNam, Object bean) {
        singletonObjects.put(beanNam, bean);
    }
}
